package 混合背包问题;

import java.util.Scanner;

public class Main {
    static int N = 1010;
    static int[] f = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        for (int i = 1; i <= n; i++) {
            int v = in.nextInt();
            int w = in.nextInt();
            int s = in.nextInt();
            if (s == 0) {
                for (int j = v; j <= m; j++) {
                    f[j] = Math.max(f[j], f[j - v] + w);
                }
            } else {
                if (s == -1) {
                    s = 1;
                }
                for (int k = 1; k <= s; k <<= 1) {
                    for (int j = m; j >= k * v; j--) {
                        f[j] = Math.max(f[j], f[j - k * v] + k * w);
                    }
                    s -= k;
                }
                if (s > 0) {
                    for (int j = m; j >= s * v; j--) {
                        f[j] = Math.max(f[j], f[j - s * v] + s * w);
                    }
                }
            }
        }
        System.out.println(f[m]);
    }
}
